package com.itheima.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
//@PropertySource("classpath:application.properties")
@EnableConfigurationProperties(JdbcProperties.class)
public class JdbcConfig {
//    @Value("${jdbc.url}")
//    private String url;
//    @Value("${jdbc.driverClassName}")
//    private String driverClassName;
//    @Value("${jdbc.username}")
//    private String username;
//    @Value("${jdbc.password}")
//    private String password;

//    @Bean
//    public DataSource dataSource(){
//        DruidDataSource druidDataSource = new  DruidDataSource();
//        druidDataSource.setUrl(url);
//        druidDataSource.setDriverClassName(driverClassName);
//        druidDataSource.setUsername(username);
//        druidDataSource.setPassword(password);
//        return druidDataSource;
//    }
    @Bean
    public DataSource dataSource(JdbcProperties jdbcProperties)
    {
        DruidDataSource druidDataSource=new DruidDataSource();
        druidDataSource.setUrl(jdbcProperties.getUrl());
        druidDataSource.setDriverClassName(jdbcProperties.getDriverClassName());
        druidDataSource.setUsername(jdbcProperties.getUsername());
        druidDataSource.setPassword(jdbcProperties.getPassword());
        return druidDataSource;
    }
}
